package com.tdkj.action.backstage.decorate;

import javax.annotation.Resource;

import org.hibernate.Query;

import com.tdkj.action.BaseAction;
import com.tdkj.model.decorate.BeanDiamond;
import com.tdkj.service.decorate.IBeanDiamondService;

public class DiamondAction extends BaseAction {
    
	private IBeanDiamondService diamondService;
	
	private BeanDiamond bean ;
	
	public String execute() {
		
		String hql = "select bean from " + BeanDiamond.class.getName() + " as bean order by bean.id";
		Query query = this.createQuery(hql);
		this.queryByPage(query, "diamondAction.action", 10);
		return "success";
	}
	
	public String add() {
		diamondService.save(bean);
		return execute();
	}
	
	public String update() {
		diamondService.saveOrUpdate(bean, BeanDiamond.class);
		return execute();
	}

	public String delete() {
		diamondService.delete(bean.getId(), BeanDiamond.class);
		return execute();
	}
	
	public String edit() {
		bean = diamondService.findById(bean.getId(), BeanDiamond.class);
		return "edit";
	}

	public BeanDiamond getBean() {
		return bean;
	}

	public void setBean(BeanDiamond bean) {
		this.bean = bean;
	}

	@Resource
	public void setDiamondService(IBeanDiamondService diamondService) {
		this.diamondService = diamondService;
	}

	
}
